// 渲染主页面逻辑

import Header from '../../components/Header';
import LeftTree from '../../components/LeftTree';
import AddNewPage from '../../components/AddNewPage';
import MainTable from '../../components/MainTable';

import language from '../../language';

import EmptyPage from '../../../../../hrpub//common/components/emptyImg';

import instant from '../../instant';

export default function renderPage() {
    const {
        humanResourceOrganizationValue,
        page,
        hasSearched,
        selectedRows,
        pageInfo,
        showTableCheckbox,
        addPageTemplate,
        pageFrom,
        show_on_job_psn,
        include_child_orgs,
        include_child_depts,
        imageData,
        subTableEditable,
        disableUpload,
        currentSelectDepartment,
        disabledTreeNodeList,
        mainTableHeight,
        pageHeight
    } = this.state;
    let darkTheme = document.body.className.includes('c-lightapp-front-black');

    if (page === 'main' || page === 'adjust-sort') {
        return (
            <div className="main-page">
                <Header
                    {...this.props}
                    page={page}
                    pageInfo={pageInfo}
                    ref={ref => this.headerRef = ref}
                    updateState={this.updateState}
                    humanResourceOrganizationValue={humanResourceOrganizationValue}
                    getMainTableData={this.getMainTableData}
                    hasSearched={hasSearched}
                    selectedRows={selectedRows}
                    getRef={this.getRef}
                    toEditPage={this.toEditPage}
                    deleteMainTableRow={this.deleteMainTableRow}
                    batchAddSub={this.batchAddSub}
                    exportPhoto={this.exportPhoto}
                    showHisJobModal={this.showHisJobModal}
                    showReportTo={this.showReportTo}
                    createUser={this.createUser}
                    show_on_job_psn={show_on_job_psn}
                    include_child_orgs={include_child_orgs}
                    include_child_depts={include_child_depts}
                    goBackToMainPage={this.goBackToMainPage}
                    importPhotos={this.importPhotos}
                    print={this.print}
                    fileManager={this.fileManager}
                    printOutput={this.printOutput}
                    exportPsn={this.exportPsn}
                    setButtonStatus2={this.setButtonStatus2}
                    getLeftTreeData={this.getLeftTreeData}
                    addPerson={this.addPerson}
                    currentSelectDepartment={currentSelectDepartment}
                    previewCardView={this.previewCardView}
                />
                <div
                    className="tree-table entry-mng-page-content"
                    style={{
                        height: `${pageHeight - 38}px`
                    }}
                >
                    <div
                        className="left-content"
                        style={{
                            height: `${pageHeight - 38}px`,
                            display: humanResourceOrganizationValue.refpk ? 'block' : 'none',
                            borderColor: darkTheme ? '#39393f' : '#d7d7d7'
                        }}
                    >
                        <div className="left-tree-wrapper">
                            <LeftTree
                                {...this.props}
                                ref={ref => this.leftRef = ref}
                                selectTree={this.selectTreeNode}
                                currentSelectDepartment={currentSelectDepartment}
                                updateState={this.updateState}
                                humanResourceOrganizationValue={humanResourceOrganizationValue}
                                getLeftTreeData={this.getLeftTreeData}
                                disabledTreeNodeList={disabledTreeNodeList}
                                doDisabledTreeNodeList={this.doDisabledTreeNodeList}
                            />
                        </div>
                    </div>
                    <div
                        className="right-content"
                        ref={ref => instant.rightRef = ref}
                        style={{
                            marginLeft: humanResourceOrganizationValue.refpk ? '250px' : '0',
                            width: humanResourceOrganizationValue.refpk ? 'auto' : '100%',
                            height: `${pageHeight - 38}px`
                        }}
                    >
                        {
                            humanResourceOrganizationValue.refpk ?
                                <MainTable
                                    {...this.props}
                                    updateState={this.updateState}
                                    handleTableSelect={this.handleTableSelect}
                                    getMainTableData={this.getMainTableData}
                                    pageInfo={pageInfo}
                                    showTableCheckbox={showTableCheckbox}
                                    toEditPage={this.toEditPage}
                                    selectAll={this.selectAll}
                                    mainTableHeight={mainTableHeight}
                                    page={page}
                                    pageHeight={pageHeight}
                                /> :
                                <EmptyPage
                                    height={456}
                                    text={language['hi6007-000191']/**暂无数据，请先选择人力组织 */}
                                />
                        }

                    </div>
                </div>
            </div>
        );
    } else if (page === 'add-new') {
        return (
            <AddNewPage
                {...this.props}
                updateState={this.updateState}
                addPageTemplate={addPageTemplate}
                goBackToMainPage={this.goBackToMainPage}
                pageFrom={pageFrom}
                humanResourceOrganizationValue={humanResourceOrganizationValue}
                copyRow={this.copyRow}
                deleteRow={this.deleteRow}
                addRow={this.addRow}
                imageData={imageData}
                subTableEditable={subTableEditable}
                getModifyData={this.getModifyData}
                selectedRows={selectedRows}
                cancelEdit={this.cancelEdit}
                setButtonStatus2={this.setButtonStatus2}
                toEditPage={this.toEditPage}
                setUpLoaderRef={this.setUpLoaderRef}
                getRef={this.getRef}
                MultiInit={this.props.MultiInit}
                disableUpload={disableUpload}
            />
        );
    }
}
